/**
 * Project Name:gc_sms_hss
 * File Name:EmployeeStatusServiceImpl.java
 * Package Name:com.clps.dev.sms.service.sm.impl
 * Copyright (c) 2018, erwin.wang@clpsglobal.com All Rights Reserved.
 *
 */
package com.clps.dev.sms.service.sm.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.clps.dev.sms.common.result.ResponseResult;
import com.clps.dev.sms.common.result.ResultState;
import com.clps.dev.sms.common.result.ResultType;
import com.clps.dev.sms.common.service.impl.BaseServiceImpl;
import com.clps.dev.sms.dao.sm.EmployeeStatusDao;
import com.clps.dev.sms.entity.sm.EmployeeStatus;
import com.clps.dev.sms.service.sm.IEmployeeStatusService;
import com.clps.dev.sms.util.result.ResponseResultUtil;

/**
 * ClassName: EmployeeStatusServiceImpl
 * Description: 员工状态服务的功能实现
 *
 * @author erwin.wang
 * @version V1.0
 * @since JDK 1.8
 * @date 2018-12-05 15:34:18
 */
@Service
@Transactional
public class EmployeeStatusServiceImpl extends BaseServiceImpl<EmployeeStatus> implements IEmployeeStatusService {


	public EmployeeStatusServiceImpl() {
		super(EmployeeStatus.class);
	}

	@Autowired
	private EmployeeStatusDao esDao;
	
	private Logger logger = Logger.getLogger(EmployeeStatusServiceImpl.class);
	
	/**
	 * @see com.clps.dev.sms.service.sm.IEmployeeStatusService#addEmployeeStatus(com.clps.dev.sms.entity.sm.EmployeeStatus)
	 */
	@Override
	public ResponseResult<EmployeeStatus> addEmployeeStatus(EmployeeStatus es) {
		int id = esDao.save(es);
		if (id > 0) {
			logger.debug(ResultType.ADD_SUCCESS);
			return ResponseResultUtil.success(ResultState.SAVESUCCESS, ResultType.ADD_SUCCESS);
		} else {
			logger.debug(ResultType.ADD_FAULT);
			return ResponseResultUtil.error(ResultState.SAVEERROR, ResultType.ADD_FAULT);
		}
	}

	/**
	 * @see com.clps.dev.sms.service.sm.IEmployeeStatusService#editEmployeeStatus(com.clps.dev.sms.entity.sm.EmployeeStatus)
	 */
	@Override
	public ResponseResult<EmployeeStatus> editEmployeeStatus(EmployeeStatus es) {
		if (es.getEmployeeStatusName() == null || 
				es.getEmployeeStatusCreatedEmployeeId() == null||
				es.getEmployeeStatusCreatedTime() == null) {
				logger.debug(ResultType.INPUT_NULL);
				return ResponseResultUtil.error(ResultState.NOT_ACCEPTABLE, ResultType.INPUT_NULL);
		}
		int resultId = esDao.update(es, es.getEmployeeStatusId());
		if (resultId > 0) {
			logger.debug(ResultType.UPDATE_SUCCESS);
			return ResponseResultUtil.success(ResultState.UPDATE_SUCCESS, ResultType.UPDATE_SUCCESS);
		} else {
			logger.debug(ResultType.UPDATE_FAULT);
			return ResponseResultUtil.error(ResultState.UPDATE_FAULT, ResultType.UPDATE_FAULT);
		}
	}

	/**
	 * @see com.clps.dev.sms.service.sm.IEmployeeStatusService#queryEmployeeStatus(java.lang.Integer)
	 */
	@Override
	public ResponseResult<EmployeeStatus> queryEmployeeStatus(Integer esId) {
		if(esId==null){
			logger.debug(ResultType.INPUT_NULL);
			return ResponseResultUtil.error(ResultState.NOT_ACCEPTABLE, ResultType.INPUT_NULL);
		}
		EmployeeStatus empStatus = esDao.queryById(esId);
		return ResponseResultUtil.success(ResultState.QUERYSUCCESS, ResultType.QUERY_SUCCESS,empStatus);
	}

	/**
	 * @see com.clps.dev.sms.service.sm.IEmployeeStatusService#deleteEmployeeStatus(java.lang.Integer)
	 */
	@Override
	public ResponseResult<EmployeeStatus> deleteEmployeeStatus(Integer esId) {
		if(esId==null){
			logger.debug(ResultType.INPUT_NULL);
			return ResponseResultUtil.error(ResultState.NOT_ACCEPTABLE, ResultType.INPUT_NULL);
		}
		Integer resultId = esDao.deleteById(esId);
		if(resultId>0){
			logger.debug(ResultType.UPDATE_SUCCESS);
			return ResponseResultUtil.success(ResultState.REMOVESUCCESS, ResultType.UPDATE_SUCCESS);
		} else {
			logger.debug(ResultType.UPDATE_FAULT);
			return ResponseResultUtil.error(ResultState.REMOVEERROR, ResultType.UPDATE_FAULT);
		}
	}

	/**
	 * @see com.clps.dev.sms.service.sm.IEmployeeStatusService#queryAllEmployeeStatus()
	 */
	@Override
	public ResponseResult<EmployeeStatus> queryAllEmployeeStatus() {
		List<EmployeeStatus> esList = esDao.queryALl();
		return ResponseResultUtil.success(ResultState.QUERYSUCCESS, ResultType.QUERY_SUCCESS,esList);
	}

	/**
	 * @see com.clps.dev.sms.service.sm.IEmployeeStatusService#isValidByEmployeeStatusName(java.lang.String)
	 */
	@Override
	public ResponseResult<EmployeeStatus> isValidByEmployeeStatusName(String esName) {
		if (esName == null){
				logger.debug(ResultType.INPUT_NULL);
				return ResponseResultUtil.error(ResultState.NOT_ACCEPTABLE, ResultType.INPUT_NULL);
		}
		Integer resultId = esDao.verifyUniqueByESName(esName);
		if(resultId==0){
			logger.debug(ResultType.CONTENT_NOT_REPEAT);
			return ResponseResultUtil.success(ResultState.QUERYSUCCESS, ResultType.CONTENT_NOT_REPEAT);
		} else {
			logger.debug(ResultType.CONTENT_REPEAT);
			return ResponseResultUtil.success(ResultState.QUERYERROR, ResultType.CONTENT_NOT_REPEAT);
		}
	}

}
